package org.example.ch05.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName RabbitConfig
 * @Description TODO
 * @Author Kx
 * @Date 2025/10/11 15:05
 * @Version 1.0
 */
@Configuration
public class RabbitConfig {
    /**
     * 定义交换机
    */
    public static final String EXCHANGE_NAME = "order.change";

    /**
     * 队列的名称
     */
    public static final String QUEUE_NAME = "order.queue";

    /**
     * 定义路由key
     */
    public static final String ROUTING_KEY = "order.key";

    /**
     * @return org.springframework.amqp.core.Exchange
     * @author: kx
     * @date: 2025/10/11 15:10
     * @description: 装配 Direct 类型的交换机
     */
    /*@Bean
    public Exchange exchange() {
        // return new TopicExchange(EXCHANGE_NAME);
        // return new FanoutExchange(EXCHANGE_NAME);
        // 创建交换机
        return new DirectExchange(EXCHANGE_NAME);
    }

    *//**
     * @author: kx
     * @date: 2025/10/11 15:12
     * @return org.springframework.amqp.core.Queue
     * @description: 装配队列
    *//*
    @Bean
    public Queue queue() {
        // 第二个参数表示队列是否持久化， true 为持久化
        return new Queue(QUEUE_NAME, false);
    }

    *//**
     * @author: kx
     * @date: 2025/10/11 15:13
     * @return org.springframework.amqp.core.Binding
     * @description: 将队列和交换机进行绑定
    *//*
    @Bean
    public Binding binding() {
        return BindingBuilder.bind(queue())
                .to(exchange())
                .with(ROUTING_KEY)
                .noargs();
    }*/

    /**
     * 替换默认的SimpleMessageConverter序列化器
     */
    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }
}

